package com.example.MatchGame;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.media.MediaPlayer;
import android.view.MotionEvent;

import com.example.PullGame.Constant;
import com.example.PullGame.Menu;
import com.example.PullGame.PullDrawView;
import com.example.PullGame.PullGameOver;
import com.example.PullGame.PullGameView;
import com.example.PullGame.PullState;
import com.example.wonderfulradish.R;

import java.io.IOException;
import java.util.Random;

/**
 * Created by 陈勇劲 on 2017/10/3.
 */

public class MatchGamePlay implements MatchState{
    //设置不通难度的数值
    private final int EASY=8;
    private final int NORMAL=6;
    private final int HARD=4;
    private final int VERYHARD=2;


    private Resources res;
    private Bitmap blueGameBg,pinkGameBg,greenGamePg,gameBg,holeBitmap,mainBitmap,luboBitmap;
    private Bitmap redBitmap,yellowBitmap,orangeBitmap,greenBitmap,purpleBitmap,blueBitmap;
    private Bitmap smallred,smallyellow,smallorange,smallgreen,smallpurple,smallblue,selectColor;
    private Bitmap timeTextBitmap,progressBitmap,orangeProgressBitmap,pointButtonBitmap,pinkProgressBitmap;

    private Bitmap[] returnButtonBitmap,pushButtonBitmap,luboBit;
    private Rect gameBgRect,buttonRect,timeTextRect,progressRect,pushButtonRect,pointButtonRect,selectColorRect;
    private Rect[] holeRects,mainRect,luboRect;
    private boolean[] mainF;
    private boolean isPressed;
    private MatchMenu menu;
    private int score,startCountdown,timer,level,gameCountdown;
    private MediaPlayer mp;
    private MatchDrawView mainActivity;
    private final int RED=1;
    private final int BLUE=2;
    private final int GREEN=3;
    private final int PURPLE=4;
    private final int YELLOW=5;
    private final int ORANGE=6;

    public MatchGamePlay(Resources res, MatchMenu menu, MatchDrawView mainActivity){

        this.mainActivity=mainActivity;
        this.res=res;
        this.menu=menu;
        load();//加载
    }

    public void load(){
        //加载背景图以及矩形块等,背景有三种
        greenBitmap= BitmapFactory.decodeResource(res, R.drawable.youxi2_orangebj_png);
        blueGameBg=BitmapFactory.decodeResource(res,R.drawable.youxi2_greenbj_png);
        pinkGameBg=BitmapFactory.decodeResource(res,R.drawable.youxi2_pinkbj_png);
        //随机选3个背景
        Random random=new Random();
        int m=random.nextInt(3);
        if (m==0){
            gameBg=greenGamePg;
        }else if (m==1){
            gameBg=pinkGameBg;
        }else if(m==2){
            gameBg=blueGameBg;
        }
        //背景矩形块绘制
        gameBgRect=new Rect(menu.getBackgroundRect());
        //洞口图片的加载
        holeBitmap=BitmapFactory.decodeResource(res, R.drawable.youxi2_orangefang_png);
        //放在数组之中
        holeRects=new Rect[9];
        //设置开始游戏前的倒计时,时间为60/20秒。
        startCountdown=60;
        //timer用来控制阿狸出现速度
        timer=0;
        //难度等级
        level=EASY;
        //游戏时间，时间为1200/20秒
        //暂时设置为200/20
        gameCountdown=200;



        //以下为洞的矩形块排列坐标大小等
        int left=(int) ((gameBgRect.left+20)*Menu.widthM);
        //背景left的值加屏幕的值*屏幕高度比例，保证适应性
        int top=(int) ((gameBgRect.top+Constant.SCREEN_HEIGHT*7/5)*Menu.heightM);
        int right=(int) ((gameBgRect.left+20+holeBitmap.getWidth())*Menu.widthM);
        int bottom=(int) ((gameBgRect.top+Constant.SCREEN_HEIGHT*7/5+holeBitmap.getHeight())*Menu.heightM);

        holeRects[0]=new Rect(left, top, right, bottom);
        left=(int) (holeRects[0].right+20*Menu.widthM);
        top= holeRects[0].top;
        right=(int) (holeRects[0].right+(20+holeBitmap.getWidth())*Menu.widthM);
        bottom=holeRects[0].bottom;
        holeRects[1]=new Rect(left, top, right, bottom);

        left=(int) (holeRects[1].right+20*Menu.widthM);
        top= holeRects[1].top;
        right=(int) (holeRects[1].right+(20+holeBitmap.getWidth())*Menu.widthM);
        bottom=holeRects[1].bottom;
        holeRects[2]=new Rect(left, top, right, bottom);


        left=holeRects[0].left;
        top=(int) (holeRects[0].bottom+80*Menu.heightM);
        right=holeRects[0].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[3]=new Rect(left, top, right, bottom);

        left=holeRects[1].left;
        top=(int) (holeRects[1].bottom+80*Menu.heightM);
        right=holeRects[1].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[4]=new Rect(left, top, right, bottom);

        left=holeRects[2].left;
        top=(int) (holeRects[2].bottom+80*Menu.heightM);
        right=holeRects[2].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[5]=new Rect(left, top, right, bottom);

        left=holeRects[3].left;
        top=(int) (holeRects[3].bottom+80*Menu.heightM);
        right=holeRects[3].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[6]=new Rect(left, top, right, bottom);

        left=holeRects[4].left;
        top=(int) (holeRects[4].bottom+80*Menu.heightM);
        right=holeRects[4].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[7]=new Rect(left, top, right, bottom);

        left=holeRects[5].left;
        top=(int) (holeRects[5].bottom+80*Menu.heightM);
        right=holeRects[5].right;
        bottom=(int) (top+holeBitmap.getHeight()*Menu.heightM);
        holeRects[8]=new Rect(left, top, right, bottom);

        //小萝卜
        smallred=BitmapFactory.decodeResource(res,R.drawable.red_small);
        smallorange=BitmapFactory.decodeResource(res,R.drawable.orange_small);
        smallyellow=BitmapFactory.decodeResource(res,R.drawable.yellow_small);
        smallblue=BitmapFactory.decodeResource(res,R.drawable.blue_small);
        smallgreen=BitmapFactory.decodeResource(res,R.drawable.green_small);
        smallpurple=BitmapFactory.decodeResource(res,R.drawable.purple_small);


        //被选中萝卜的颜色
        Random select=new Random();
        int selectlubo=select.nextInt(6);
        if (selectlubo==RED){
            selectColor=smallred;
        }else if (selectlubo==ORANGE){
            selectColor=smallorange;
        }else if (selectlubo==YELLOW){
            selectColor=smallyellow;
        }else if (selectlubo==BLUE){
            selectColor=smallblue;
        }else if(selectlubo==GREEN){
            selectColor=smallgreen;
        }else{
            selectColor=smallpurple;
        }
        //小萝卜的位置
        left=(int) ((gameBgRect.left+20)*Menu.widthM);
        top= (int) (gameBgRect.top+gameBgRect.height()*2/14);
        right=(int) ((gameBgRect.left+20+selectColor.getWidth()*3/2)*Menu.widthM);
        bottom=(int) (gameBgRect.top+gameBgRect.height()*3/14);
        selectColorRect=new Rect(left,top,right,bottom);


        //萝卜贴图
        blueBitmap=BitmapFactory.decodeResource(res,R.drawable.blue_luobo_mid);
        redBitmap=BitmapFactory.decodeResource(res,R.drawable.red_luobo_small);
        yellowBitmap=BitmapFactory.decodeResource(res,R.drawable.yellow_luobo_mid);
        orangeBitmap=BitmapFactory.decodeResource(res,R.drawable.orange_luobo_big);
        greenBitmap=BitmapFactory.decodeResource(res,R.drawable.green);
        purpleBitmap=BitmapFactory.decodeResource(res,R.drawable.purple);

        //将各颜色的罗卜装入数组中
        luboBit=new Bitmap[6];
        luboBit[0]=blueBitmap;
        luboBit[1]=redBitmap;
        luboBit[2]=yellowBitmap;
        luboBit[3]=orangeBitmap;
        luboBit[4]=greenBitmap;
        luboBit[5]=purpleBitmap;

        //选择应该击中的萝卜 //选中图片和矩形块
        switch(selectlubo){
            case RED:
                mainBitmap=redBitmap;
                break;
            case GREEN:
                mainBitmap=greenBitmap;
                break;
            case ORANGE:
                mainBitmap=orangeBitmap;
                break;
            case BLUE:
                mainBitmap=blueBitmap;
                break;
            case YELLOW:
                mainBitmap=yellowBitmap;
                break;
            case PURPLE:
                mainBitmap=purpleBitmap;
        }

        luboRect=new Rect[1];
        luboRect[0]=new Rect(0, 0, (int) (mainBitmap.getWidth()*Menu.heightM),
                (int) (mainBitmap.getHeight()*Menu.widthM));
        
        mainRect = new Rect[1];
        mainRect[0]=new Rect(0, 0, (int) (mainBitmap.getWidth()*Menu.heightM),
                (int) (mainBitmap.getHeight()*Menu.widthM));


        //先前选中颜色是否被打到的判断
        mainF=new boolean[1];

        //返回按钮图片和矩形块
        returnButtonBitmap=new Bitmap[2];
        returnButtonBitmap[0]=BitmapFactory.decodeResource(res, R.drawable.icon_back_83px);
        returnButtonBitmap[1]=BitmapFactory.decodeResource(res, R.drawable.icon_play);
        left=(int) ((gameBgRect.left+20)*Menu.widthM);
        top=(int) ((gameBgRect.top+80)*Menu.heightM);
        right=(int) ((gameBgRect.left+20+returnButtonBitmap[0].getWidth())*Menu.widthM);
        bottom=(int) ((gameBgRect.top+80+returnButtonBitmap[0].getHeight())*Menu.heightM);
        buttonRect=new Rect(left, top, right, bottom);
        
        
        //停止按钮图片和矩形快
        pushButtonBitmap=new Bitmap[2];
        pushButtonBitmap[0]=BitmapFactory.decodeResource(res, R.drawable.icon_play);
        pushButtonBitmap[1]=BitmapFactory.decodeResource(res, R.drawable.icon_stop_83px);
        left=(int) ((gameBgRect.left+gameBgRect.right*5/4)*Menu.widthM);
        top=(int) ((gameBgRect.top+80)*Menu.heightM);
        right=(int) ((gameBgRect.left+gameBgRect.right*5/4+pushButtonBitmap[0].getWidth())*Menu.widthM);
        bottom=(int) ((gameBgRect.top+80+pushButtonBitmap[0].getHeight())*Menu.heightM);
        pushButtonRect=new Rect(left, top, right, bottom);

        //提示按钮
        pointButtonBitmap=BitmapFactory.decodeResource(res,R.drawable.icon_point_83px);
        left=(int) ((gameBgRect.left+gameBgRect.right*6/4)*Menu.widthM);
        top=(int) ((gameBgRect.top+80)*Menu.heightM);
        right=(int) ((gameBgRect.left+gameBgRect.right*6/4+pushButtonBitmap[0].getWidth())*Menu.widthM);
        bottom=(int) ((gameBgRect.top+80+pushButtonBitmap[0].getHeight())*Menu.heightM);
        pointButtonRect=new Rect(left, top, right, bottom);


       //绘制时钟的图像,为时钟添加初始化位置

        timeTextBitmap=BitmapFactory.decodeResource(res,R.drawable.icon_time);
        left=(int) ((gameBgRect.left+gameBgRect.right)*Menu.widthM);
        top=(int) ((gameBgRect.top+80)*Menu.heightM);
        right=(int) ((gameBgRect.left+gameBgRect.right+pushButtonBitmap[0].getWidth())*Menu.widthM);
        bottom=(int) ((gameBgRect.top+80+pushButtonBitmap[0].getHeight())*Menu.heightM);
        timeTextRect=new Rect(left, top, right, bottom);


        //进度条位置
        progressBitmap=BitmapFactory.decodeResource(res,R.drawable.progress1);
        orangeProgressBitmap=BitmapFactory.decodeResource(res,R.drawable.progress2);
        pinkProgressBitmap=BitmapFactory.decodeResource(res,R.drawable.progress3);
        left=(int) (Constant.SCREEN_WIDTH*1/9);
        top= (int) (gameBgRect.top+gameBgRect.height()*2/14);
        right=(int) (Constant.SCREEN_WIDTH*8/9);
        bottom=(int) (gameBgRect.top+gameBgRect.height()*2/12);
        progressRect=new Rect(left,top,right,bottom);



        //背景音乐的加载
        mp=MediaPlayer.create(mainActivity, R.raw.sugar);
        mp.setLooping(true);
        try {
            //背景音乐准备
            mp.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //背景音乐播放
        mp.start();
    }

    @Override
    public void draw(Canvas canvas, Paint paint) {
        //画游戏元素的方法
        drawGame(canvas, paint);
        //画分数的方法
        drawScore(canvas, paint);
        //画等级以及时间的方法
        drawLevel(canvas, paint);
    }


    private void drawLevel(Canvas canvas, Paint paint) {
        //文字大小
        paint.setTextSize(200*Menu.widthM);
        //开始倒计时大于0的时候,画倒计时数字.
        if(startCountdown>=0){
            canvas.drawText(startCountdown/20+1+"", Constant.SCREEN_WIDTH/2-100*Menu.widthM, Constant.SCREEN_HEIGHT/2, paint);
        }
        //开始倒计时大于-1时,自减,小于-1,游戏倒计时开始自减
        if(startCountdown>-1){
            startCountdown--;
        }else if (startCountdown<=-1) {
            gameCountdown--;
        }

        //如果分数大于60,游戏倒计时不小于零,游戏等级为简单.等级增加,并重置开始倒计时和游戏倒计时
        //下面的同理.
        if(score>=3&&gameCountdown>=0&&level==EASY){
            level=NORMAL;
            startCountdown=0;
            gameCountdown=600;
        }else if (score>=6&&gameCountdown>=0&&level==NORMAL) {
            level=HARD;
            startCountdown=0;
            gameCountdown=600;
        }
        else if (score>=9&&gameCountdown>=0&&level==HARD) {
            level=VERYHARD;
            startCountdown=0;
            gameCountdown=600;
        }


        //如果游戏时间小于0.音乐停止,游戏结束
        if(gameCountdown<0){
            mp.stop();
            mp.reset();
            MatchGameView.matchState=new MatchGameOver(res, score,menu,mainActivity);
        }



        //画笔实心
        paint.setStyle(Paint.Style.FILL);
        //画笔文字大小
        paint.setTextSize(40*Menu.heightM);
        //画笔颜色红
        paint.setColor(Color.RED);
        //字体尺寸
        paint.setTextSize(25);
        //画时间
        //canvas.drawText("时间："+gameCountdown/20, gameBgRect.right-230*Menu.widthM,
        //        gameBgRect.top+gameBgRect.height()*3/5, paint);
        paint.setTextSize(50);

        //canvas.drawText(""+gameCountdown/20, gameBgRect.left+gameBgRect.width()*4/8,
        //       gameBgRect.top+gameBgRect.height()*1/21, paint);

        canvas.drawText(""+gameCountdown/20,(gameBgRect.left+950)*Menu.widthM,
                (gameBgRect.top+250)*Menu.heightM, paint);


        //画等级
        switch (level) {
            case EASY:
                //canvas.drawText("简单", gameBgRect.right-180*Menu.widthM,
                //        gameBgRect.top+gameBgRect.height()*9/12, paint);
                canvas.drawBitmap(progressBitmap,null,progressRect,paint);
                break;
            case NORMAL:
                //canvas.drawText("普通", gameBgRect.right-180*Menu.widthM,
                //        gameBgRect.top+gameBgRect.height()*9/12, paint);
                canvas.drawBitmap(orangeProgressBitmap,null,progressRect,paint);
                break;
            case HARD:
                //canvas.drawText("困难", gameBgRect.right-180*Menu.widthM,
                //        gameBgRect.top+gameBgRect.height()*9/12, paint);
                canvas.drawBitmap(pinkProgressBitmap,null,progressRect,paint);
                break;
            case VERYHARD:
                //canvas.drawText("没法玩", gameBgRect.right-180*Menu.widthM,
                //        gameBgRect.top+gameBgRect.height()*9/12, paint);

                canvas.drawBitmap(orangeProgressBitmap,null,progressRect,paint);
                break;
        }
    }

    
    //画游戏
    private void drawGame(Canvas canvas, Paint paint) {
        //画笔设置为黑色
        paint.setColor(Color.BLACK);
        //先画屏幕大小的黑布
        canvas.drawRect(0, 0, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT, paint);
        //画背景图
        canvas.drawBitmap(gameBg, null, gameBgRect, paint);

        //画计时器
        canvas.drawBitmap(timeTextBitmap,null,timeTextRect,paint);

        //画被选中的按钮
        canvas.drawBitmap(selectColor,null,selectColorRect,paint);

        //画提示按钮
        canvas.drawBitmap(pointButtonBitmap,null,pointButtonRect,paint);
        //画洞
        for(int i=0;i<holeRects.length;i++){

            canvas.drawBitmap(holeBitmap, null, holeRects[i], paint);
        }
        //每刷新一次画面，timer+1
        timer++;
        //随机数
        Random random=new Random();
        //如果 阿狸被打  或者 开始倒计时为零  或者  计数器到达level
        int n;
        if(mainF[0]||startCountdown==0||timer==level){
            //得到一个洞总数的随机数
            n=random.nextInt(holeRects.length);
            //将阿狸的矩形块移到这个洞上
            mainRect[0].offsetTo(holeRects[n].left+holeRects[n].width()/2-mainRect[0].width()/2,
                    holeRects[n].top-mainRect[0].height()+(int)(20*Menu.heightM));
            //如果洞口数不等于n就贴上其他图
            for(int i=0;i<holeRects.length;i++){
                int s;
                s=random.nextInt(4);
                if (i!=n){
                    luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                    if (startCountdown<0)
                    canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                }
              /*  int s;
                if(i!=n) {
                    switch (i) {
                        case 1:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 2:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 3:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 4:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 5:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 6:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 7:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 8:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        case 9:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                        default:
                            luboRect[0].offsetTo(holeRects[i].left+holeRects[i].width()/2-luboRect[0].width()/2,
                                    holeRects[i].top-luboRect[0].height()+(int)(20*Menu.heightM));
                            s=random.nextInt(6);
                            canvas.drawBitmap(luboBit[s],null,luboRect[0],paint);
                            break;
                    }
                }*/
            }

            //阿狸被打改为false
            mainF[0]=false;
            //计数器清零
            timer=0;
        }

        //当阿狸没有被打并且开始倒计时小于0的时候，开始画阿狸
        if(!mainF[0]&&startCountdown<0){
            canvas.drawBitmap(mainBitmap, null, mainRect[0], paint);
    }


        //画停止按钮
        if(isPressed){
            canvas.drawBitmap(pushButtonBitmap[1],null,pushButtonRect,paint);
        }else{
            canvas.drawBitmap(pushButtonBitmap[0], null,pushButtonRect,paint);
        }

        //画返回按钮
        if(isPressed){
            canvas.drawBitmap(returnButtonBitmap[1], null, buttonRect,paint);
        }else{
            canvas.drawBitmap(returnButtonBitmap[0], null, buttonRect,paint);
        }
    }

    private void drawScore(Canvas canvas, Paint paint) {
        //画笔无锯齿
        paint.setAntiAlias(true);
        //画笔实心
        paint.setStyle(Paint.Style.FILL);
        //画笔红色
        paint.setColor(Color.RED);
        //字体大小
        paint.setTextSize(40*Menu.heightM);
        String s=""+score+"/18";
        //画得分
        paint.setTextSize(50);

        int left=(int) (Constant.SCREEN_WIDTH*7/9);
        int top= (int) (gameBgRect.top+gameBgRect.height()*3/14);
        int right=(int) (Constant.SCREEN_WIDTH*8/9);
        int bottom=(int) (gameBgRect.top+gameBgRect.height()*2/12);
        Rect r=new Rect(left,top,right,bottom);
        canvas.drawText(s, r.left+20*Menu.widthM,r.bottom-100*Menu.heightM, paint);
    }

    @Override
    public void touch(MotionEvent event) {//触摸方法,和menu里的类似
        // TODO Auto-generated method stub
        int x=(int) event.getX();
        int y=(int) event.getY();
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if(mainRect[0].contains(x,y)){//触摸到阿狸的时候,分数自加.
                    mainF[0]=true;
                    score++;

                }
                if(buttonRect.contains(x, y)){
                    isPressed=true;
                }
                break;

            case MotionEvent.ACTION_UP:
                if(buttonRect.contains(x, y)){//返回时背景音乐停止
                    mp.stop();
                    mp.reset();
                    MatchGameView.matchState=this.menu;
                }
                isPressed=false;
                break;
        }
    }

}


